#include "DataConvert.h"

void
DataConvert::fromBinary(const string &data, QVariant &var)
{
    QByteArray rawdata = QByteArray::fromRawData(&data[0], data.size());
    QBuffer buf(&rawdata);
    buf.open(QBuffer::ReadOnly);
    {
        QDataStream input(&buf);
        input >> var;
    }
    buf.close();
}

void
DataConvert::toBinary(const QVariant &var, string &data)
{
    QBuffer buf;
    buf.open(QBuffer::ReadWrite);
    {
        QDataStream output(&buf);
        output << var;
    }
    buf.close();
    data.assign(buf.data().constData(), buf.data().length());
}
